﻿using System.ComponentModel.DataAnnotations.Schema;

namespace FrameworkCore.Migrations.Data;

/// <summary>
/// 基础实体
/// </summary>
public class BaseEntity : IEntity<long>
{
    /// <summary>
    ///获取或设置实体标识符
    /// </summary>
    [DatabaseGenerated(DatabaseGeneratedOption.None)]
    public virtual long Id { get; set; }

    private readonly List<DomainEvent> _domainEvents = new();

    [NotMapped] public IReadOnlyCollection<DomainEvent> DomainEvents => _domainEvents.AsReadOnly();

    public void AddDomainEvent(DomainEvent domainEvent)
    {
        _domainEvents.Add(domainEvent);
    }

    public void RemoveDomainEvent(DomainEvent domainEvent)
    {
        _domainEvents.Remove(domainEvent);
    }

    public void ClearDomainEvents()
    {
        _domainEvents.Clear();
    }

    /// <summary>
    /// 获取或设置排序
    /// </summary>
    public virtual int? Sort { get; set; }

    /// <summary>
    /// 获取或设置描述
    /// </summary>
    public virtual string? Description { get; set; }
}
